$(function(){

	//一级导航的添加 
	$('.Nav1Add').click(function(){
		var Nav1Name = $('input[name=Nav1Name]').val().trim();
		var Nav1Order = $('input[name=Nav1Order]').val().trim();
		if(!Nav1Name || !Nav1Order){
			alert('数据不得为空！');
			exit;
		}
		var p = /^[1-9][0-9]{0,3}$/;
		if(!p.test(Nav1Order)){
			alert('序号必须为小于四位的正整数！');
			exit;
		}
		$.ajax({
			url:'/index.php/Admin/ModelNav1/Nav1_Add',
			type:'post',
			data:{
				Nav1Name:Nav1Name,
				Nav1Order:Nav1Order
			},
			success:function(res){
			//	alert(res);
				if(res > 0){
					alert('添加成功！');
				}else if(res=='e2'){
					alert('导航名以存在');
				}else{
					alert('添加失败！');
				}
				location.reload(true);
			}
		});
	});



	//一级导航的删除 
	$('.Nav1Del').click(function(){
		if(!confirm('确认删除?')){
			exit;
		}
		nid = $(this).attr('data');
		$.ajax({
			url:'/index.php/Admin/ModelNav1/Nav1_Del',
			data:{
				nid:nid
			},
			type:'post',
			success:function(res){
				if(res > 0){
					alert('删除成功！');
					location.reload(true);
				}
			}
		});
	});


	//全选|取消
	$('input[name=CheckAll]').change(function(){
		if($(this).is(':checked')){
			$('input[name=Nids]').each(function(){
				this.checked=true;
			});
		}else{
			$('input[name=Nids]').attr('checked',false);
		}
	});


	//多选删除 
	$('.Nav1Dels').click(function(){
		if(!confirm('确认删除选中？')){
			exit;
		}
		var arr = [];
		$('input[name=Nids]').each(function(){
			if(this.checked){
				arr.push($(this).val());
			}
		});
		if(arr.length <=0){
			exit;
		}
		var arr_nid = arr.join(',');
		$.ajax({
			url:'/index.php/Admin/ModelNav1/Nav1_Del',
			data:{
				nid:arr_nid
			},
			type:'post',
			success:function(res){
				if(res > 0){
					alert('删除成功！');
					location.reload(true);
				}
			}	
		});
	});
});